package com.mojo.concurrent.concurrent_01_thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 线程实现方式之Callable
 *
 * @author <a href="mailto:mojo_jj@163.com">Mojo</a>
 */
public class ThreadDemo03 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> task = new FutureTask<>(new MyCallable());
        Thread thread = new Thread(task);
        thread.start();
        System.out.println(task.get());
    }
}

class MyCallable implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {

        try {
            Thread.sleep(10000L);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return 10;
    }
}
